let s = "pwwkew";
let lengthOfLongestSubstring = function (s) {
  let left = 0;
  let right = 0;
  let maxLength = 0;
  let hash = new Map(); 

  while (right < s.length) {
    if (hash.has(s[right])) {
        // 如果字符重复，更新 left 为重复字符的下一个位置
        left = Math.max(left, hash.get(s[right]) + 1);
    }
    // 更新字符的索引
    hash.set(s[right], right);
    // 更新最大长度
    maxLength = Math.max(maxLength, right - left + 1);
    // 移动右指针
    right++;
  }

  return maxLength
};

console.log(lengthOfLongestSubstring(s))
